<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>VUE3: 动态绑定属性</title>
  </head>
  <body>
    <div id="app"></div>

    <template id="tpl">
      <div :[attrName]="attrValue">绑定单个属性(不生效)</div>
      <div v-bind="attrs">绑定整个对象</div>
    </template>

    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
      Vue.createApp({
        template: "#tpl",
        data() {
          return {
            attrName: "foo",
            attrValue: "bar",
            attrs: {
              title: "绑定整个对象",
              class: "foobar",
              style: { color: "red", margin: "1rem auto", cursor: "pointer" },
            },
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
